package com.world.rickcloudendpoint.api.controller;

import com.world.rickcloudendpoint.common.Result;
import com.world.rickcloudendpoint.common.annotation.UserActionLogger;
import com.world.rickcloudendpoint.common.exception.ClientException;
import com.world.rickcloudendpoint.common.exception.ModuleException;
import com.world.rickcloudendpoint.models.mongo.OptLog;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: jlsong
 * @date: 2022/04/06 06:09:23
 * @version: 1.0
 */
@Log4j2
@RestController
public class DemoController implements DemoApi {


    @Resource
    MongoTemplate mongoTemplate;

    @Override
    @UserActionLogger(title = "在api上12扎实你好i", businessType = "为了老师")
    public Result<Object> showDemo(String payload) throws ClientException, ModuleException {
//        Query query = new Query(Criteria.where("time").lt(1649250893788L).gte(1649250695840L));
        Criteria criteria = new Criteria();
        criteria.andOperator(Criteria.where("time").gte(1649250695840L), Criteria.where("time").lt(1649250893788L));
        Query query = new Query(criteria);
        List<OptLog> data = mongoTemplate.find(query, OptLog.class);
        return Result.ok(data);
    }
}
